module libeventd.evbuffer.Internal;

import
	libeventd.Types;

extern(C):

struct evbuffer_cb_entry {
	TAILQ_ENTRY!(evbuffer_cb_entry)	next;
	union {
		evbuffer_cb_func		cb_func;
		evbuffer_cb		cb_obsolete;
	} //cb;
	void *		cbarg;
	ev_uint32_t	flags;
}

struct evbuffer_cb_queue{
	mixin TAILQ_HEAD!(evbuffer_cb_entry);
}

struct evbuffer {
	evbuffer_chain*	first;
	evbuffer_chain*	last;
	evbuffer_chain**	last_with_datap;

	size_t		total_len;
	size_t		n_add_for_cb;
	size_t		n_del_for_cb;

version(_EVENT_DISABLE_THREAD_SUPPORT){}else{
	void* 		lock ;
}

	ubyte[4]		__flag ; // own_lock , freeze_start	, freeze_end, deferred_cbs,  version(Windows){is_overlapped}
	deferred_cb_queue*	cb_queue;
	int			refcnt;
	deferred_cb	deferred;
	evbuffer_cb_queue		callbacks;
	bufferevent*		parent;
}


struct evbuffer_chain {
	evbuffer_chain*	next;
	size_t	buffer_len;
	ev_off_t	misalign;
	size_t	off;
	ev_uint	flags;
	ubyte*	buffer;
}


struct evbuffer_chain_fd {
	int fd;
}

struct evbuffer_chain_reference {
	evbuffer_ref_cleanup_cb cleanupfn;
	void*	extra;
}

void _evbuffer_incref(evbuffer *buf);
void _evbuffer_incref_and_lock(evbuffer *buf);
void _evbuffer_chain_pin(evbuffer_chain *chain, ev_uint flag);
void _evbuffer_chain_unpin(evbuffer_chain *chain, ev_uint flag);
void _evbuffer_decref_and_unlock(evbuffer *buffer);
ev_int _evbuffer_expand_fast(evbuffer *, size_t, ev_int);
ev_int _evbuffer_read_setup_vecs( evbuffer *buf, ev_ssize_t howmuch,  evbuffer_iovec *vecs, ev_int n_vecs,  evbuffer_chain ***chainp, ev_int exact);
void evbuffer_set_parent(evbuffer *buf,  bufferevent *bev);